package br.com.negocio;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.com.entidade.Funcionario;
import br.com.logica.Logica;

public class AcessoGerenciarFuncionario implements Logica {

	@Override
	public void executa(HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		RequestDispatcher rd = null;

		Funcionario gerente;

		HttpSession sessao = request.getSession();
		try {
			gerente = (Funcionario) sessao.getAttribute("gerente_autenticado");
			System.out.println("Nome do gerente: " + gerente.getNome());
			if (gerente instanceof Funcionario) {
				rd = request.getRequestDispatcher("gerenciarFuncionario.jsp");
				rd.forward(request, response);
			} else {
				rd = request.getRequestDispatcher("index.jsp?msg=naoEhGerente");
				rd.forward(request, response);
			}
		} catch (Exception e) {
			rd = request.getRequestDispatcher("index.jsp?msg=logueComoGerente");
			rd.forward(request, response);
		}

	}

}
